<template>
	<view id="moments">
 <!-- 头像 -->
		<view class="home-pic">
			<view class="home-pic-base">
				<view class="top-pic">
					<image class="header" :src="'../../static/headimage/'+imgAddress+'.jpg'"></image>
				</view>
			
			</view>
		</view>

		<view class="moments__post" v-for="(f,index) in forums" :key="f.id" >
			<view class="post-left">
				<!-- <image class="post_header" :src="post.header_image"></image> -->
			</view> 

			<view class="post_right">
				<text class="post-username">{{f.stuNumber}}</text>
				<view id="paragraph" class="paragraph">{{f.note}}</view>
				
				<!-- 相册 -->
				<!-- <view class="thumbnails">
					<view :class="post.content.images.length === 1?'my-gallery':'thumbnail'" v-for="(image, index_images) in post.content.images" :key="index_images">
						<image class="gallery_img" lazy-load mode="aspectFill" :src="image" :data-src="image" @tap="previewImage(post.content.images,index_images)"></image>
					</view>
				</view> -->
				<!-- 资料条 -->
				<view class="toolbar">
					<!-- <view class="timestamp">{{post.timestamp}}</view> -->
					<view class="like" @tap="like(index)">
						<image src='../../static/index/islike.png'></image>
						{{f.likes}}
					</view>
					<view class="comment" @tap="comment1(index)">
						<image src="../../static/index/comment.png"></image>
					</view>
				</view>
				<!-- 评论区 -->
				<view class="post-footer">
					
					<view class="load1">
						<!-- <text @click="showallc(index)" v-if="showcomments">显示全部评论</text>
						<text @click="noshowallc(index)" v-if="noshowcomments">收起评论</text> -->
						<text @click="showallc(index)">
						                {{ f.showComments ? '收起评论' : '显示全部评论' }}
						            </text>
						<view  class="footer_content" v-for="(c,comment_index) in f.comments" :key="comment_index"v-if="f.showComments">
							<text class="comment-nickname">{{c.stuNumber}}: <text class="comment-content">{{c.content}}</text></text>
						</view>
					</view>
					
				</view>
			</view>
			<!-- 结束 post -->
		</view>

		<!-- <view class="foot" v-show="showInput">
			<chat-input @send-message="send_comment" @blur="blur" :focus="focus" :placeholder="input_placeholder"></chat-input>
			
		</view> -->
		<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
	</view>

</template>

<script>
	// import chatInput from '../../components/im-chat/chatinput.vue'; //input框
	//  import postData from '../../common/index/index.post.data.js';//朋友圈数据
	
	export default {
		// components: {
		// 	chatInput
		// },
		data() {
			return {
				// showcomments:true,
				// noshowcomments:false,
				comment:{
					id:'',
					forumId:'',
					content:'',
					stuNumber:'',
				},
				
				
				forum:{
					id:'',
					stuNumber:'',
					note:'',
					likes:'',
				},
				forums:[],
				
				stu:'',
				
				
				
				
				
				
				
				// posts: postData,//模拟数据
				user_id: 4,
				username: 'Liuxy',

				index: '',
				comment_index: '',

				input_placeholder: '评论', //占位内容
				focus: false, //是否自动聚焦输入框
				is_reply: false, //回复还是评论
				showInput: false, //评论输入框

				screenHeight: '', //屏幕高度(系统)
				platform: '',
				windowHeight: '' ,//可用窗口高度(不计入软键盘)
				
				loadMoreText: "加载中...",
				showLoadMore: false,
				imgAddress:""
			}
		},
		// mounted() {
			
		// 	uni.getStorage({
		// 		key: 'posts',
		// 		success: function (res) {
		// 			console.log(res.data);
		// 			this.posts = res.data;
		// 		}
		// 	});

		// },
		onLoad() {
			const  value1=uni.getStorageSync('user1')
			const  value2=uni.getStorageSync('admin')
			const shu1=uni.getStorageSync('wen');
			const shu2=uni.getStorageSync('shu01');
			if(shu1=="1"&&shu2!="12"){
				this.imgAddress=value1.imgAddress;
			}if(shu1=="2"&&shu2!="12"){
				this.imgAddress=value2.imgAddress;
			}			
			uni.request({ 
				url:'http://192.168.137.139:8080/showForum',
				method:"GET",
				
				success:(res)=> {
					
					if(res.data.code*1==200){
						
					  console.log(res.data.result);
						//this.$u.toast('登录成功');
					  console.log(4)
					 this.forums=res.data.result
					
					}
					else{
						this.$u.toast('上传失败!');
						
					}
				}
				
			})
			
			
			// uni.getSystemInfo({ //获取设备信息
			// 	success: (res) => {
			// 		this.screenHeight = res.screenHeight;
			// 		this.platform = res.platform;
			// 	}
			// });
			// uni.startPullDownRefresh();
		},
	
		onNavigationBarButtonTap(e) {//监听标题栏点击事件
			if (e.index == 0) {
				uni.navigateTo({
					url:'/pages/luntanpublish/luntanpublish'
				})
			}
		},
		computed:{
			
		},
		methods: {
			back() {
				uni.navigateBack();
			},
	
			showallc(index){
				this.showcomments=false;
				this.noshowcomments=true;
				this.forum.id=index+1;
				console.log(this.forum.id)
				this.comment.forumId=this.forum.id;
				console.log(this.comment.forumId)
				
				
				uni.request({
					url:'http://192.168.137.139:8080/getComments',
					method:'POST',
					data:this.comment,
					success:(res)=> {
						
						if(res.data.code*1==200){
							
						  console.log(res.data.result);
							//this.$u.toast('登录成功');
						  console.log(8)
						this.forums[index].comments=res.data.result;
						this.forums[index].showComments = !this.forums[index].showComments;
						this.$forceUpdate();
						console.log(this.forums[index].comments)
						console.log(9)
						}
						
						else{
							this.$u.toast('上传失败!');
							
						}
					}
				})
			},
			
			
			like(index) {
				console.log(4)
				console.log(index)
				this.forum.id=index+1;
				console.log(this.forum.id)
				console.log(9)
				uni.request({
					url:'http://192.168.137.139:8080/likeForum',
					method:'POST',
					data:this.forum,
					success:(res)=> {
						
						if(res.data.code*1==200){
							
						  console.log(res.data.result);
							//this.$u.toast('登录成功');
						  console.log(8)
						  console.log(this.forums)
						  setTimeout(() => {
						  	this.$router.go(0)
						  }, 500)
						}
						else{
							this.$u.toast('上传失败!');
							
						}
					}
					
				})
			},
			
			
			blur: function() {
				this.init_input();
			},
			comment1(index){
				console.log(index)
				uni.navigateTo({
					url:'/pages/luntanpublish/luntancomment?index=' + index
				})
			},
		
			
		}
	}
</script>

<style scoped>
	
	@import url('../../common/index/index.css');
</style>
